﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    /// <summary>
    /// 劳保物品领用规则
    /// </summary>
    public class Work_ArticleRuleInfo
    {
        DataAccessWork_ArticleRule DAS;
        /// <summary>
        /// 行记录
        /// </summary>
        private int rowcount = 0;
        public int _rowcount
        {
            get { return rowcount; }
        }
        /// <summary>
        /// 是否获得行记录
        /// </summary>
        /// <param name="isGetCount"></param>
        public Work_ArticleRuleInfo(bool isGetCount)
        {
            DAS = new DataAccessWork_ArticleRule();
            if (isGetCount)
            {
                rowcount = DAS.GetWork_ArticleRuleCount("");
            }

        }
        //构造函数
        public Work_ArticleRuleInfo() { }
        /// <summary>
        /// Id
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 规则名称
        /// </summary>
        public string ArticleName { get; set; }
        /// <summary>
        /// 几个月
        /// </summary>
        public int Month { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
        /// <summary>
        /// 获取劳保物资规则数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_ArticleRuleCount(string Condition)
        {
            return DAS.GetWork_ArticleRuleCount(Condition);
        }


        /// <summary>
        /// 保存劳保物资规则
        /// </summary>
        /// <param name="idab"></param>
        /// <returns></returns>
        public int SaveWork_ArticleRule(Work_ArticleRuleInfo sdiDetail)
        {
            object[] idpara = new object[] { sdiDetail.ID, sdiDetail.ArticleName, sdiDetail.Month, sdiDetail.Remark };
            return DAS.SaveWork_ArticleRule(idpara);
        }

        /// <summary>
        /// 获取劳保物资规则不分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Work_ArticleRuleInfo> GetAllArticleRule(string condition)
        {
            IList<Work_ArticleRuleInfo> Idalist = new List<Work_ArticleRuleInfo>();
            DataSet ds = DAS.GetAllWork_ArticleRule(condition);
            Work_ArticleRuleInfo ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_ArticleRuleInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    ArticleName = Convert.ToString(item[1]),
                    Month = Convert.ToInt32(item[2]),
                    Remark = Convert.ToString(item[3])
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }


        /// <summary>
        /// 根据ID获取劳保物资规则实体类
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public Work_ArticleRuleInfo GetAllArticleRule(int Id)
        {
            DataRow item = DAS.GetAllWork_ArticleRule(" And id=" + Id).Tables[0].Rows[0];
            Work_ArticleRuleInfo ideinfo = new Work_ArticleRuleInfo()
            {
                ID = Convert.ToInt32(item[0]),
                ArticleName = Convert.ToString(item[1]),
                Month = Convert.ToInt32(item[2]),
                Remark = Convert.ToString(item[3])
            };
            return ideinfo;
        }


        /// <summary>
        /// 获取劳保物资规则分页
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public IList<Work_ArticleRuleInfo> GetAllArticleRule(string condition, int pagesize, int startindex)
        {
            IList<Work_ArticleRuleInfo> Idalist = new List<Work_ArticleRuleInfo>();
            DataSet ds = DAS.GetAllWork_ArticleRule(condition, pagesize, startindex);
            Work_ArticleRuleInfo ideinfo;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                ideinfo = new Work_ArticleRuleInfo()
                {
                    ID = Convert.ToInt32(item[0]),
                    ArticleName = Convert.ToString(item[1]),
                    Month = Convert.ToInt32(item[2]),
                    Remark = Convert.ToString(item[3])
                };
                Idalist.Add(ideinfo);
            }
            return Idalist;
        }



        /// <summary>
        /// 删除劳保物资规则
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int DeleteArticleRule(int Id)
        {
            return DAS.DeleteWork_ArticleRule(Id.ToString());
        }
    }
}
